<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>编辑商品</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <script type="text/javascript" src="./js/urlToFile.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-body">
    <form class="layui-form">
        <input type="hidden" name="cid" id="cid">
        <div class="layui-form-item">
            <label  class="layui-form-label">
                商品名称
            </label>
            <div class="layui-input-inline">
                <input type="text" id="goodstitle" name="goodstitle" class="layui-input" placeholder="请输入商品 名称">
            </div>
        </div>

        <div class="layui-form-item">
            <label  class="layui-form-label">
                商品现价
            </label>
            <div class="layui-input-inline">
                <input type="text" id="currentprice" name="currentprice" class="layui-input" placeholder="请输入商品现价">
            </div>
        </div>

<!--        <div class="layui-form-item">-->
<!--            <label  class="layui-form-label">-->
<!--                新品-->
<!--            </label>-->
<!--            <div class="layui-input-inline">-->
<!--                <input type="text" id="newstate" name="newstate" class="layui-input">-->
<!--            </div>-->
<!--        </div>-->

        <div class="layui-form-item">
            <div class="layui-input-inline">
                <label class="layui-form-label">是否新品</label>
                <input type="checkbox" lay-skin="switch" lay-text="是|否" value="0" id="newstate" name="newstate" lay-filter="newstate">
            </div>
            <div class="layui-input-inline">
                <label class="layui-form-label">是否热卖</label>
                <input type="checkbox" lay-skin="switch" lay-text="是|否" value="0" id="hotstate" lay-filter="hotstate">
            </div>
            <div class="layui-input-inline">
                <label class="layui-form-label">是否推荐</label>
                <input type="checkbox" lay-skin="switch" lay-text="是|否" value="0" id="recomstate" lay-filter="recomstate">
            </div>
        </div>



        <div class="layui-form-item">
            <label  class="layui-form-label">
            </label>
            <button  class="layui-btn" lay-filter="editGoods" lay-submit="" id="editGoods">
                保存
            </button>
        </div>
    </form>
</div>
<script>

    function GetQueryValue(queryName) {
        var query = decodeURI(window.location.search.substring(1));
        var vars = query.split("&");
        for (var i = 0; i < vars.length; i++) {
            var pair = vars[i].split("=");
            if (pair[0] == queryName) { return pair[1]; }
        }
        return null;
    }

    var newstate=GetQueryValue('newstate');
    var hotstate=GetQueryValue('hotstate');
    var recomstate=GetQueryValue('recomstate');
    console.log(newstate);
    console.log(hotstate);
    console.log(recomstate);
    if (newstate==1){
        $('#newstate').prop("checked", true);
    }
    if (hotstate==1){
        $('#hotstate').prop("checked", true);
        $('#hotstate').val(1)
    }
    if (recomstate==1){
        $('#recomstate').prop("checked", true);
        $('#recomstate').val(1)
    }



    layui.use(['upload','form','layer','laydate','dropdown'], function(){
        $ = layui.jquery;
        var form = layui.form
            ,layer = layui.layer
            ,upload = layui.upload
            ,laydate=layui.laydate

        //监听指定开关
        form.on('switch(newstate)', function(data){
            this.checked?data.value=1:data.value=0; //更改选中和未选中时，传动后台的值，此时选中传1，未选中传0。
             newstate=data.value;
        })
        form.on('switch(hotstate)', function(data){
            this.checked?data.value=1:data.value=0; //更改选中和未选中时，传动后台的值，此时选中传1，未选中传0。
            hotstate=data.value;
        })
        form.on('switch(recomstate)', function(data){
            this.checked?data.value=1:data.value=0; //更改选中和未选中时，传动后台的值，此时选中传1，未选中传0。
            recomstate=data.value;
        })

        form.on('submit(editGoods)',function (data){
            var formData=new FormData()
            formData.append("goodstitle",$('#goodstitle').val())
            formData.append("currentprice",$('#currentprice').val())
            formData.append("newstate",newstate)
            formData.append("hotstate",hotstate)
            formData.append("recomstate",recomstate)
            console.log("--------------------")
            console.log($('#goodstitle').val())
            console.log($('#currentprice').val())
            console.log(newstate)
            console.log(hotstate)
            console.log(recomstate)
            $.ajax({
                url: 'goods/editGoods',
                type:'post',
                data:formData,
                processData:false,
                async:false,
                dataType:'json',
                success:function (res){
                    alert('修改成功')
                }
            })
        })




    });
</script>
<script>var _hmt = _hmt || []; (function() {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
})();</script>
</body>

</html>